import request from '@/utils/request'

const userApi = {
  Login: '/user/login',
  Logout: '/user/logout',
  SendSms: '/account/sms',
  // get my info
  UserInfo: '/user-manage/show-details/',
  UserEdit: '/user-manage/update-user',
  UserMenu: '/user/nav',
  UserList: '/user-manage/show-users',
  UserDelete: '/user-manage/delete/',
  UserCreate: '/user-manage/add-user'
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login (parameter) {
  return request({
    url: userApi.Login,
    method: 'post',
    data: parameter
  })
}

export function getInfo (id) {
  return request({
    url: userApi.UserInfo + id,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function setInfo (parameter) {
  return request({
    url: userApi.UserEdit,
    method: 'post',
    data: parameter
  })
}

export function getCurrentUserNav () {
  return request({
    url: userApi.UserMenu,
    method: 'get'
  })
}

export function logout () {
  return request({
    url: userApi.Logout,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step (parameter) {
  return request({
    url: userApi.twoStepCode,
    method: 'post',
    data: parameter
  })
}

export function getSmsCaptcha (parameter) {
  return request({
    url: userApi.SendSms,
    method: 'post',
    data: parameter
  })
}

export function getUserList () {
  return request({
    url: userApi.UserList,
    method: 'get'
  })
}

export function deleteUser (id) {
  return request({
    url: userApi.UserDelete + id,
    method: 'get'
  })
}

export function createUser (parameter) {
  return request({
    url: userApi.UserCreate,
    method: 'post',
    data: parameter
  })
}
